package com.copa.j47;

/**
 * @author copa
 * @createDate 2023-03-08 7:47
 * @function
 */
public class Test1 {

    public int maxValue(int[][] grid) {
        int row = grid.length;
        int col = grid[0].length;
        int[][] result = new int[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if (i > 0) {
                    result[i][j] = Math.max(result[i][j], result[i - 1][j]);
                }
                if (j > 0) {
                    result[i][j] = Math.max(result[i][j], result[i][j - 1]);
                }
                result[i][j] += grid[i][j];
            }
        }
        return result[row - 1][col - 1];
    }

    public static void main(String[] args) {
        int[][] grid = {
                {1,3,1},
                {1,5,1},
                {4,2,1}
        };
        System.out.println(new Test1().maxValue(grid));
    }
}
